package com.nky.common;

import com.nky.common.constant.StatusCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    /**
     * 状态码（成功或失败），前端和后端约定好
     */
    private String code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回给前端的数据
     */
    private Object data;

    public static Result success() {
        return new Result(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMsg(), null);
    }

    public static Result success(Object data) {
        return new Result(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMsg(), data);
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error() {
        return new Result(StatusCode.SYSTEM_ERROR.getCode(), StatusCode.SYSTEM_ERROR.getMsg(), null);
    }
}
